package com.gdpu.controller;

import com.gdpu.api.CommonPage;
import com.gdpu.api.CommonResult;
import com.gdpu.dto.ImsPurchaseOrderDto;
import com.gdpu.model.ImsPurchaseOrder;
import com.gdpu.service.ImsPurchaseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:weiming
 * @Date:2021/5/27
 * 进货模块
 */
@Api(tags = "进货模块")
@RestController
public class ImsPurchaseOrderController {

    @Autowired
    private ImsPurchaseOrderService imsPurchaseOrderService;

    @GetMapping("/purorders/")
    @ApiOperation("分页获取所有进货")
    public CommonResult list(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
                           @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize){
        CommonPage list = imsPurchaseOrderService.list(pageNum, pageSize);
        return CommonResult.success(list);
    }

    @ApiOperation("根据订单查询订货商品")
    @GetMapping("/purorders/details/{id}")
    public CommonResult orderitem(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
                             @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize){
        CommonPage list = imsPurchaseOrderService.list(pageNum, pageSize);
        return CommonResult.success(list);
    }

    @PostMapping("/purorders/")
    @ApiOperation("进货")
    public CommonResult add(@Validated @RequestBody ImsPurchaseOrder imsPurchaseOrder){
        int count = imsPurchaseOrderService.add(imsPurchaseOrder);
        if(count == 1){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("批量导入")
    @PostMapping("/purorders/batch")
    public CommonResult addList( @RequestBody List<ImsPurchaseOrderDto> imsPurchaseOrders){
        int count = imsPurchaseOrderService.addBatch(imsPurchaseOrders);
        if(count != 0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("退货操作")
    @DeleteMapping("/purorders/{id}")
    public CommonResult delete(@PathVariable Integer id){
        System.out.println(id);
        return CommonResult.failed();
    }



}
